home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 26
/
Cream of the Crop 26.iso
/
program
/
snpd9707.zip
/
DATE.CPP
< prev
next >
Wrap
Text File
|
1997-07-05
|
9KB
|
378 lines
.I 0 1
// +++Date last modified: 05-Jul-1997
.D 1 1
.I 19 8
zDate::week_day zDate::BeginDSTDay = zDate::sun;
zDate::month zDate::BeginDSTMonth = zDate::apr;
zDate::week_day zDate::EndDSTDay = zDate::sun;
zDate::month zDate::EndDSTMonth = zDate::oct;
zDate::zDate()
{
Set(jan, 1, 1);
.D 20 8
.I 31 1
Set(aMonth, aDay, aYear);
.D 32 1
.I 36 5
m_day = 31;
m_month = dec;
m_year = year - 1;
m_dayno = MakeDayNumber();
FromDayNumber(m_dayno + dayOfYear);
.D 37 5
.I 46 6
m_month = aMonth;
m_day = aDay;
m_year = aYear;
m_dayno = MakeDayNumber();
return *this;
.D 47 6
.I 56 4
m_month = aDate.m_month;
m_day = aDate.m_day;
m_year = aDate.m_year;
m_dayno = aDate.m_dayno;
.D 57 4
.I 64 1
FromDayNumber(nJulian);
.D 65 1
.I 69 4
m_month = (month)(tmDate->tm_mon + 1);
m_day = tmDate->tm_mday;
m_year = tmDate->tm_year + 1900;
m_dayno = MakeDayNumber();
.D 70 4
.I 78 5
time_t secs_now = time(0);
struct tm *time_now = localtime(&secs_now);
zDate today(time_now);
return today;
.D 79 5
.I 88 1
return Boolean(m_dayno != aDate.m_dayno);
.D 89 1
.I 94 1
return Boolean(m_dayno == aDate.m_dayno);
.D 95 1
.I 100 1
return Boolean(m_dayno < aDate.m_dayno);
.D 101 1
.I 106 1
return Boolean(m_dayno <= aDate.m_dayno);
.D 107 1
.I 112 1
return Boolean(m_dayno > aDate.m_dayno);
.D 113 1
.I 118 1
return Boolean(m_dayno >= aDate.m_dayno);
.D 119 1
.I 124 6
m_day = aDate.m_day;
m_month = aDate.m_month;
m_year = aDate.m_year;
m_dayno = aDate.m_dayno;
return *this;
.D 125 6
.I 135 4
static const int days[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
if( aYear == ReformYear && aMonth == ReformMonth ) return 21;
return days[aMonth] + (feb == aMonth && IsLeapYear(aYear));
.D 136 4
.I 144 3
zDate first(jan, 1, m_year);
return 1 + (int)(m_dayno - first.m_dayno);
.D 145 3
.I 152 4
int days = 365 + IsLeapYear(year);
// 10 days cancelled by the reform of pope Gregor XIII
if( year == ReformYear ) return days - 10;
else return days;
.D 153 4
.I 161 5
if( year % 4 ) return False; // if not divisible by 4, not leap
if( year < ReformYear ) return True; // before this year, all were leap
if( year % 100 ) return True; // by 4, but not by 100 is leap
if( year % 400 ) return False; // not by 100 and not by 400 not leap
return True;
.D 162 5
.I 171 5
return Boolean(
aYear > 0
&& aMonth >= jan && aMonth <= dec
&& aDay > 0 && aDay <= DaysInMonth(aMonth, aYear)
);
.D 172 5
.I 181 6
int age = m_year - birthday.m_year - 1;
if( m_month > birthday.m_month ) age++;
else if( m_month == birthday.m_month && m_day >= birthday.m_day ) age++;
return age;
.D 182 6
.I 192 1
return zDate(m_dayno + (long)nDays);
.D 193 1
.I 198 1
return zDate(m_dayno + nDays);
.D 199 1
.I 204 1
return zDate(m_dayno - (long)nDays);
.D 205 1
.I 210 1
return zDate(m_dayno - nDays);
.D 211 1
.I 216 1
return (long)(m_dayno - aDate.m_dayno);
.D 217 1
.I 222 2
FromDayNumber(m_dayno + (long)nDays);
return *this;
.D 223 2
.I 229 2
FromDayNumber(m_dayno + nDays);
return *this;
.D 230 2
.I 236 2
FromDayNumber(m_dayno + 1L);
return *this;
.D 237 2
.I 243 4
zDate date(*this);
FromDayNumber(m_dayno + 1L);
return date;
.D 244 4
.I 252 2
FromDayNumber(m_dayno - 1L);
return *this;
.D 253 2
.I 260 4
zDate date(*this);
FromDayNumber(m_dayno - 1L);
return date;
.D 261 4
.I 269 2
FromDayNumber(m_dayno - (long)nDays);
return *this;
.D 270 2
.I 276 2
FromDayNumber(m_dayno - nDays);
return *this;
.D 277 2
.I 283 3
zDate first(jan, 1, m_year);
return 1 + int((m_dayno - first.m_dayno + 1) / 7);
.D 284 3
.I 291 3
int abs_mday = m_day + zDate(m_month, 1, m_year).DayOfWeek() - 1;
return 1 + ((abs_mday - DayOfWeek()) / 7);
.D 292 3
.I 299 1
return zDate(dec, 31, year).WeekOfYear();
.D 300 1
.I 305 4
zDate date(*this);
date += (long)nWeeks * 7L;
return date;
.D 306 4
.I 314 12
zDate date(*this);
int delta = nYears > 0 ? -1 : 1;
int year = m_year;
long days = 0;
while( nYears ){
nYears += delta;
year -= delta;
days += DaysInYear(year);
}
date += (-delta * days);
return date;
.D 315 12
.I 330 1
return DayNumber();
.D 331 1
.I 340 6
switch( index ){
case 0 : return m_day;
case 1 : return m_month;
case 2 : return m_year - 1900;
default: return -1;
}
.D 341 6
.I 351 1
return DaysInMonth(m_month, m_year);
.D 352 1
.I 357 1
return DaysInYear(m_year);
.D 358 1
.I 363 1
return WeeksInYear(m_year);
.D 364 1
.I 369 1
return IsValid(m_month, m_day, m_year);
.D 370 1
.I 375 1
return IsLeapYear(m_year);
.D 376 1
.I 381 20
long days;
long year = (long)m_year - 1L;
// get all days plus all leap years, minus non-leap years
days = year * 365L + year / 4L - year / 100L + year / 400L;
// the years before 1582 were all leap if divisible by 4
if( year > ReformYear ) days += 12;
else{
days += year / 100L;
days -= year / 400L;
}
// get the days for the month up to the current one
for( int i = jan; i < m_month; ++i )
days += DaysInMonth((month)i, m_year);
// now add the current days of the month
days += m_day;
// now adjust for the 10 missing days (Oct 4 - Oct 15, 1582)
if( days > ReformDayNumber ) days -= 10L;
// we have the current day number now
return days;
.D 382 20
.I 406 3
const week_day wdays[7] = {sun,mon,tue,wed,thu,fri,sat};
return wdays[(int)(((m_dayno % 7) + 5) % 7)];
.D 407 3
.I 414 30
m_dayno = dayno;
if( dayno > ReformDayNumber ) dayno += 10L;
m_year = (int)(dayno / 365);
m_day = (int)(dayno % 365L);
if( m_year < 1700 ) m_day -= (m_year / 4);
else{
m_day -= (m_year / 4);
m_day += (m_year / 100);
m_day -= (m_year / 400);
m_day -= 12;
}
while( m_day <= 0 ){
m_day += (365 + IsLeapYear(m_year));
m_year--;
}
// m_year is the number of elapsed years, add 1 to get current
m_year += 1;
// figure out the month and current day too
for( m_month = jan; m_month <= dec; m_month = (month)(m_month + 1) ){
int days = DaysInMonth(m_month, m_year);
if( m_day <= days ) break;
else m_day -= days;
}
.D 415 30
.I 449 1
return IsDST(*this);
.D 450 1
.I 460 4
zDate date(BeginDSTMonth, 1, year);
while( BeginDSTDay != date.DayOfWeek() ) date++;
return date;
.D 461 4
.I 469 4
zDate date(EndDSTMonth, 31, year);
while( EndDSTDay != date.DayOfWeek() ) date--;
return date;
.D 470 4
.I 478 1
return BeginDST(m_year);
.D 479 1
.I 484 1
return EndDST(m_year);
.D 485 1
.I 490 1
return Boolean( date >= date.BeginDST() && date <= date.EndDST() );
.D 491 1
.I 496 1
return MoonPhase(*this);
.D 497 1
.I 502 8
ulong phase = date.m_dayno;
phase *= 9693L;
phase /= 35780L;
phase -= 4L;
phase %= 8L;
return (moon_phase)phase;
.D 503 8
.I 515 1
return Easter(m_year);
.D 516 1
.I 525 15
int c, n, k, i, j, l, m, d;
c = year / 100;
n = year - 19 * (year / 19);
k = (c - 17) / 25;
i = c - c / 4 - (c - k) / 3 + 19 * n + 15;
i = i - 30 * (i / 30);
i = i - (i / 28) * (1 - (i / 28) * (29 / (i + 1)) * ((21 - n) / 11));
j = year + year / 4 + i + 2 - c + c / 4;
j = j - 7 * (j / 7);
l = i - j;
m = 3 + (l + 40) / 44;
d = l + 28 - 31 * (m / 4);
return zDate((month)m, d, year);
.D 526 15
.I 555 31
int mon = m_month + nMonths;
int year = m_year;
int day = m_day;
int mdays;
while( mon < 1 ){
mon += 12;
year--;
}
while( mon > 12 ){
mon -= 12;
year++;
}
mdays = DaysInMonth((month)mon, year);
if( day > mdays ){
if( nMonths < 0 ) day = mdays - (day - mdays);
else{
day -= mdays;
mon++;
if( mon > 12 ){
year++;
mon = 1;
}
}
}
return zDate((month)mon, day, year);
}
.D 556 31